<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>跳过登录界面工具</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
      max-width: 600px;
      margin: 0 auto;
      padding: 20px;
      line-height: 1.6;
      color: #333;
    }
    h1 {
      color: #3498db;
      text-align: center;
    }
    .container {
      background-color: #f8f9fa;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    button {
      background-color: #3498db;
      color: white;
      border: none;
      padding: 12px 24px;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
      margin: 10px 5px;
      transition: background-color 0.3s;
    }
    button:hover {
      background-color: #2980b9;
    }
    .admin-btn {
      background-color: #2ecc71;
    }
    .admin-btn:hover {
      background-color: #27ae60;
    }
    .normal-btn {
      background-color: #f39c12;
    }
    .normal-btn:hover {
      background-color: #e67e22;
    }
    .clear-btn {
      background-color: #e74c3c;
    }
    .clear-btn:hover {
      background-color: #c0392b;
    }
    .status {
      margin-top: 20px;
      padding: 10px;
      border-radius: 4px;
      background-color: #e8f4fd;
      color: #2c3e50;
      display: none;
    }
    .success {
      background-color: #d5f4e6;
      color: #1e8449;
    }
    .warning {
      background-color: #fef9e7;
      color: #8e44ad;
    }
    .note {
      margin-top: 20px;
      padding: 10px;
      background-color: #f5f5f5;
      border-left: 4px solid #3498db;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>跳过登录界面工具</h1>
    
    <p>由于当前环境未连接数据库且没有密码，您可以通过以下按钮跳过登录界面：</p>
    
    <div style="text-align: center;">
      <button id="adminBtn" class="admin-btn">以管理员身份登录</button>
      <button id="normalBtn" class="normal-btn">以普通用户身份登录</button>
      <button id="clearBtn" class="clear-btn">清除登录状态</button>
    </div>
    
    <div id="status" class="status"></div>
    
    <div class="note">
      <h3>使用说明：</h3>
      <ol>
        <li>点击上方按钮后，脚本会将模拟用户信息写入浏览器的本地存储</li>
        <li>然后请刷新您的应用页面，系统将自动跳过登录界面</li>
        <li>如需清除模拟登录状态，请点击"清除登录状态"按钮</li>
        <li>此工具仅适用于开发和测试环境</li>
      </ol>
    </div>
  </div>

  <script>
    // 显示状态消息
    function showStatus(message, type) {
      const statusEl = document.getElementById('status');
      statusEl.textContent = message;
      statusEl.className = 'status ' + type;
      statusEl.style.display = 'block';
    }
    
    // 创建模拟的管理员用户信息
    function createAdminUser() {
      const mockAdminUser = {
        id: '1',
        authId: 'admin',
        username: '系统管理员',
        userType: '管理员',
        token: 'mock-admin-token-12345',
        permissions: ['all']
      };
      
      // 保存用户信息到localStorage
      localStorage.setItem('user', JSON.stringify(mockAdminUser));
      localStorage.setItem('token', mockAdminUser.token);
      localStorage.setItem('rememberedAuthId', mockAdminUser.authId);
      
      showStatus('已成功设置管理员用户！请刷新应用页面。', 'success');
    }
    
    // 创建模拟的普通用户信息
    function createNormalUser() {
      const mockNormalUser = {
        id: '2',
        authId: 'user',
        username: '普通用户',
        userType: '普通用户',
        token: 'mock-user-token-67890',
        permissions: ['basic']
      };
      
      // 保存用户信息到localStorage
      localStorage.setItem('user', JSON.stringify(mockNormalUser));
      localStorage.setItem('token', mockNormalUser.token);
      localStorage.setItem('rememberedAuthId', mockNormalUser.authId);
      
      showStatus('已成功设置普通用户！请刷新应用页面。', 'success');
    }
    
    // 清除登录状态
    function clearLoginStatus() {
      localStorage.removeItem('user');
      localStorage.removeItem('token');
      localStorage.removeItem('rememberedAuthId');
      showStatus('已清除登录状态。', 'warning');
    }
    
    // 添加按钮事件监听器
    document.getElementById('adminBtn').addEventListener('click', createAdminUser);
    document.getElementById('normalBtn').addEventListener('click', createNormalUser);
    document.getElementById('clearBtn').addEventListener('click', clearLoginStatus);
    
    // 检查是否已有登录状态
    if (localStorage.getItem('user')) {
      try {
        const user = JSON.parse(localStorage.getItem('user'));
        showStatus(`当前已登录为：${user.username}（${user.userType}）`, 'warning');
      } catch (e) {
        showStatus('检测到登录信息，但解析失败。建议清除后重新设置。', 'warning');
      }
    }
  </script>
</body>
</html>